﻿using System.Collections.Generic;

namespace Genesis.Domain
{

    using Genesis.Infrastructure;
    using Genesis.Infrastructure.Domain;

    public class Role : Entity
    {

        private IList<Mask> masks = new List<Mask>();

        private IList<Membership> memberships = new List<Membership>();

        [Signature]
        public virtual string Title { get; protected set; }
        
        public virtual string Description { get; set; }
        
        public virtual string MarkupClass { get; set; }

        public virtual bool IsAdministrator { get; set; }
        
        public virtual bool IsManager { get; set; }
        
        public virtual bool IsModerator { get; set; }
        
        public virtual bool IsBanned { get; set; }

        public virtual bool CanViewBoard { get; set; }
        
        public virtual bool CanViewOfflineBoard { get; set; }
        
        public virtual bool CanViewSignatures { get; set; }
        
        public virtual bool CanViewProfiles { get; set; }

        public virtual bool CanUseDirectory { get; set; }
        
        public virtual bool CanUseContact { get; set; }
        
        public virtual bool CanUseSearch { get; set; }

        public virtual bool CanBypassQueue { get; set; }

        public virtual bool CanPostNewThreads { get; set; }

        public virtual bool CanPostNewReplies { get; set; }
        
        public virtual bool CanReplyToOwnThreads { get; set; }
        
        public virtual bool CanReplyToOwnReplies { get; set; }
        
        public virtual bool CanReplyToOthersThreads { get; set; }
        
        public virtual bool CanReplyToOthersReplies { get; set; }
        
        public virtual bool CanEditOwnThreads { get; set; }
        
        public virtual bool CanEditOwnReplies { get; set; }
        
        public virtual bool CanEditOthersThreads { get; set; }
        
        public virtual bool CanEditOthersReplies { get; set; }
        
        public virtual bool CanDeleteOwnThreads { get; set; }
        
        public virtual bool CanDeleteOwnReplies { get; set; }
        
        public virtual bool CanDeleteOthersThreads { get; set; }
        
        public virtual bool CanDeleteOthersReplies { get; set; }
        
        public virtual bool CanMoveOwnThreads { get; set; }
        
        public virtual bool CanMoveOwnReplies { get; set; }
        
        public virtual bool CanMoveOthersThreads { get; set; }
        
        public virtual bool CanMoveOthersReplies { get; set; }
        
        public virtual bool CanCloseOwnThreads { get; set; }
        
        public virtual bool CanCloseOthersThreads { get; set; }

        public virtual bool CanOpenOwnThreads { get; set; }
        
        public virtual bool CanOpenOthersThreads { get; set; }

        public virtual bool CanManageReplyQueue { get; set; }
        
        public virtual bool CanManageThreadQueue { get; set; }
        
        public virtual bool CanManageUserQueue { get; set; }

        public virtual bool CanAdminForums { get; set; }
        
        public virtual bool CanAdminMasks { get; set; }
        
        public virtual bool CanAdminModerators { get; set; }
        
        public virtual bool CanAdminOptions { get; set; }
        
        public virtual bool CanAdminRoles { get; set; }
        
        public virtual bool CanAdminUsers { get; set; }

        public virtual IEnumerable<Mask> Masks { get { return masks; } }

        public virtual IEnumerable<Membership> Memberships { get { return memberships; } }

        public virtual void AddMask(Mask mask)
        {
            
            Logic.Check(mask != null, "Mask can not be null!");
            
            if (!masks.Contains(mask))
                masks.Add(mask);
        
        }

        public virtual void RemoveMask(Mask mask)
        {
        
            Logic.Check(mask != null, "Mask can not be null!");
            
            if (masks.Contains(mask))
                masks.Remove(mask);
        
        }

        public virtual void AddMembership(Membership membership)
        {

            Logic.Check(membership != null, "Membership can not be null!");

            if (!memberships.Contains(membership))
                memberships.Add(membership);

        }

        public virtual void RemoveMembership(Membership membership)
        {

            Logic.Check(membership != null, "Membership can not be null!");

            if (memberships.Contains(membership))
                memberships.Remove(membership);

        }

        public virtual void SetTitle(string title)
        {
        
            Logic.Check(!string.IsNullOrEmpty(title) && !string.IsNullOrWhiteSpace(title), "Title can not be null, empty or whitespace!");
            
            Title = title.Trim();
        
        }

        public Role(string title)
        {
        
            SetTitle(title);
        
        }

        protected Role() { }

    }

}